package com.cuit.qx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cuit.qx.bean.ScheduledLog;
import com.cuit.qx.dao.ScheduledLogMapper;
import com.cuit.qx.service.ScheduledLogService;
import org.apache.poi.util.LittleEndianInputStream;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *   定时器日志
 * </p>
 *
 * @author lcj
 * @since 2021-02-05
 */
@Service
public class ScheduledLogServiceImpl extends ServiceImpl<ScheduledLogMapper, ScheduledLog> implements ScheduledLogService {

    @Resource
    private ScheduledLogMapper scheduledLogMapper;

    @Override
    public void updateByTime(String methodName) {
       if (!methodName.equals("run")){
           QueryWrapper<ScheduledLog> queryWrapper = new QueryWrapper<>();
           queryWrapper.eq("method",methodName);
           ScheduledLog scheduled = scheduledLogMapper.selectOne(queryWrapper);
           ScheduledLog scheduledLog = new ScheduledLog();
           SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
           scheduledLog.setMethod(methodName);
           scheduledLog.setTime(df.format(new Date()));
           if (scheduled==null){
               if (methodName.equals("liveTImedTask")){
                   scheduledLog.setName("实况定时任务");
               }
               if (methodName.equals("liveToHistory")){
                   scheduledLog.setName("历史小时数据定时任务");
               }
               if (methodName.equals("liveToWeather")){
                   scheduledLog.setName("历史天数据定时任务");
               }
               if (methodName.equals("liveToHistoricalDay")){
                   scheduledLog.setName("历史月数据定时任务");
               }
               if (methodName.equals("liveToHistoricalMonth")){
                   scheduledLog.setName("气象站点数据定时任务");
               }
               if (methodName.equals("warningRain")){
                   scheduledLog.setName("降雨预警数据定时任务");
               }
               if (methodName.equals("warningTem")){
                   scheduledLog.setName("气温预警数据定时任务");
               }
               if (methodName.equals("warningWind")){
                   scheduledLog.setName("大风预警数据定时任务");
               }
               scheduledLogMapper.insert(scheduledLog);
           }else {
               scheduledLogMapper.update(scheduledLog,queryWrapper);
           }
       }

    }
}
